<html>
	<head><title>Enter Match</title></head>
	<body>
		<h1><center>Regions</center></h1>
		<?php
			$con = mysql_connect("oniddb.cws.oregonstate.edu","rundej-db","Hp2tYI0CxEY4U9J9");
			if (!$con)
			{
				die('Could not connect: ' . mysql_error());
			}
			mysql_select_db('rundej-db',$con);
			if (strcmp($_POST['winner'],"Region 1") == 0)
			{
				mysql_query("UPDATE Region SET Num_Wins = Num_Wins + 1 WHERE Region.Region_Name = '" . $_POST['region1'] . "';");
				mysql_query("UPDATE Region SET Num_Losses = Num_Losses + 1 WHERE Region.Region_Name = '" . $_POST['region2'] . "';");
				echo "<center><h2>Match between " . $_POST["region1"] . " and " . $_POST["region2"] . " was successfully entered!</h2><br>";
			}
			
			elseif ($_POST['winner'] == "Region 2")
			{
				mysql_query("UPDATE Region SET Num_Wins = Num_Wins + 1 WHERE Region.Region_Name = '" . $_POST['region2'] . "';");
				mysql_query("UPDATE Region SET Num_Losses = Num_Losses + 1 WHERE Region.Region_Name = '" . $_POST['region1'] . "';");
				echo "<center><h2>Match between " . $_POST["region1"] . " and " . $_POST["region2"] . " was successfully entered!</h2><br>";
			}
			
			elseif ($_POST['winner'] == "Tie") 
			{
				mysql_query("UPDATE Region SET Num_Ties = Num_Ties + 1 WHERE Region.Region_Name = '" . $_POST['region2'] . "';");
				mysql_query("UPDATE Region SET Num_Ties = Num_Ties + 1 WHERE Region.Region_Name = '" . $_POST['region1'] . "';");
				echo "<center><h2>Match between " . $_POST["region1"] . " and " . $_POST["region2"] . " was successfully entered!</h2><br>";
			}
			else
			{
				echo "<center><h2>Match between " . $_POST["region1"] . " and " . $_POST["region2"] . " was not successfully entered!</h2><br>";
			}
			echo "Region 1: " . $_POST["region1"] . "<br>";
			echo "Region 2: " . $_POST["region2"] . "<br>";
			echo "Winner: " . $_POST["winner"] . "</center>"; 	
		?>
		<center>
		<table border="1">
		<tr>
			<th>Region No.</th>
			<th>Region Name</th>
			<th>Captain No.</th>
			<th>Headquarters</th>
			<th>President Name</th>
			<th>Wins</th>
			<th>Losses</th>
			<th>Ties</th>
		</tr>	
		<?php
			$result = mysql_query("SELECT * FROM Region");
			while ($row = mysql_fetch_array($result))
			{
				echo "<tr>";
				echo "<td>" . $row['Region_No'] . "</td>";
				echo "<td>" . $row['Region_Name'] . "</td>";
				echo "<td>" . $row['Captain'] . "</td>";
				echo "<td>" . $row['Headquarters'] . "</td>";
				echo "<td>" . $row['President_Name'] . "</td>";
				echo "<td>" . $row['Num_Wins'] . "</td>";
				echo "<td>" . $row['Num_Losses'] . "</td>";
				echo "<td>" . $row['Num_Ties'] . "</td>";
				echo "</tr>";
			}
			mysql_close($con);
		?>
		</table>
		</center>
		<br>
		<br>
		<br>
		<br>
		<center>
			<a href = "http://web.engr.oregonstate.edu/~caushikh/cricket-database/">Home</a> 
			<a href = "http://web.engr.oregonstate.edu/~caushikh/cricket-database/regions.php">Regions</a> 
			<a href = "http://web.engr.oregonstate.edu/~caushikh/cricket-database/umpires.php">Umpires</a> 
			<a href = "http://web.engr.oregonstate.edu/~caushikh/cricket-database/players.php">Players</a></center> 
	</body>
</html>
